import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import './plugins/element.js'
import './assets/css/global.css'
import './assets/fonts/iconfont.css'
import axios from 'axios'
import treeTable from 'vue-table-with-tree-grid'

// 文本编辑器
import VueQuillEditor from 'vue-quill-editor'
import 'quill/dist/quill.core.css' // import styles
import 'quill/dist/quill.snow.css' // for snow theme
import 'quill/dist/quill.bubble.css' // for bubble theme

import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

Vue.config.productionTip = false

//axios请求的跟路径
axios.defaults.baseURL = 'http://192.168.131.136:8888/api/private/v1/'
//请求拦截,向服务器发请求时通过请求头传递Authorization字段
axios.interceptors.request.use((config) => {
  //在requerst拦截器中显示进度条 NProgress
  NProgress.start()
  config.headers.Authorization = sessionStorage.getItem('token')
  return config
})
//响应拦截
axios.interceptors.response.use((config) => {
  //在response拦截器中隐藏进度条
  NProgress.done()
  return config
})

Vue.prototype.$http = axios
Vue.component('tree-table', treeTable)
//注册全局文本编辑器
Vue.use(VueQuillEditor)

//定义全局过滤器(时间格式化)
Vue.filter('dateFormate', function(timestamp){
  const df = new Date(timestamp)

  const y = df.getFullYear()
  const m = (df.getMonth() + 1 + '').padStart(2, '0')
  const d = (df.getDay() + '').padStart(2, '0')

  const hh = (df.getHours() + '').padStart(2, '0')
  const mm = (df.getMinutes() + '').padStart(2, '0')
  const ss = (df.getSeconds() + '').padStart(2, '0')

  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})
new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
